#!/bin/bash
#########################################################################
# File Name: cjcp-parse.sh
# Author: Fan Yang
# mail: missdeer@dfordsoft.com
# Created Time: 2014年02月24日 星期一 20时53分58秒
#########################################################################
grep -r -a "\"issue_list\">[0-9]\+<\/td>" -o $1 | grep -o "[0-9]\+" > /tmp/cjcp.issue
grep -r -a "\"shahao_number\">[0-9]\+</span>" -o $1 | grep -o "[0-9]\+" > /tmp/cjcp.tmp
grep -r -a "\"winning_red\">[0-9]\+</td>" -o $1 | grep -o "[0-9]\+" >> /tmp/cjcp.tmp
rm -f /tmp/cjcp.data
cat /tmp/cjcp.tmp | while read c1 && read c2 && read c3 && read c4 && read c5 && read c6 && read c7 && read c8 && read c9 && read c10
do
    echo "$c1 $c2 $c3 $c4 $c5 $c6 $c7 $c8 $c9 $c10" >> /tmp/cjcp.data
done
paste -d " " /tmp/cjcp.issue /tmp/cjcp.data > /tmp/cjcp.txt
cat /tmp/cjcp.txt  | while read line
do
    issue=`echo "$line" | awk '{print $1}'`
    ball=`echo "$line" | awk '{print $2}'`
    if [[ "-$ball" != "-" ]]
    then
        valid_issue=`echo "$issue" | grep -o "[0-9]\{7,7\}"`
        if [[ "-$valid_issue" != "-" ]]
        then
            exist=`grep -r -a "$issue" $2`
            if [[ "-$exist" = "-" ]]
            then
                echo "$line" >> $2 
            fi
        fi
    fi
done
